﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class ManageStaffDAL
    {
        DBConnection cn = new DBConnection();
        public DataTable GetStaffDAL()
        {
            return cn.loadData("SELECT * FROM [User] WHERE isShow = 1;");
        }

        public void AddStaffDAL(string username, string password, string name, int male, int roleId,
            string birthday, string phone, string address, string startedDate, int isShow)
        {
            string data = "'" + username + "',"
                            + "'" + password + "',"
                            + "N'" + name + "',"
                            + male + ","
                            + roleId + ","
                            + "'" + birthday + "',"
                            + "'" + phone + "',"
                            + "N'" + address + "',"
                            + "'" + startedDate + "',"
                            + isShow;
            string sql = "INSERT [User]"
                    + "(username, password, name, gender, roleId, birthdate, phone, address, startedDate, isShow) "
                    + "VALUES (" + data + ");";
            cn.InsertToDB(sql);
        }

        public bool CheckExistedStaffDAL(string username)
        {
            return cn.checkExistedItem("SELECT * FROM [User] WHERE username = '" + username + "';");
        }

        public void UpdateStaffDAL(string userId, string username, string password, string name, int male, int roleId,
            string birthday, string phone, string address, string startedDate, int isShow)
        {
            string sql = "UPDATE [User] SET "
                            + "username = '" + username + "',"
                            + "password = '" + password + "',"
                            + "name = N'" + name + "',"
                            + "gender = " + male + ","
                            + "roleId = " +roleId + ","
                            + "birthdate = '" + birthday + "',"
                            + "phone = '" + phone + "',"
                            + "address = N'" + address + "',"
                            + "startedDate = '" + startedDate + "',"
                            + "isShow = " + isShow + " "
                            + "where userId = " + userId + ";";
            cn.InsertToDB(sql);
        }

        // Delete
        public void DeactiveStaffDAL(string userId)
        {
            string sql = "UPDATE [User] SET "
                            + "isShow = 0"
                            + "where userId = " +userId +";";
            cn.InsertToDB(sql);
        }

        public DataSet GetRoleDAL()
        {
            return cn.LoadDBComBox("SELECT * FROM Role;");
        }
    }
}
